package com.bes.opslink.aiops.server.web.controller.demo;

import com.bes.opslink.aiops.commons.dto.base.R;
import com.bes.opslink.aiops.server.api.dto.DemoDTO;
import com.bes.opslink.aiops.server.entity.demo.Demo;
import com.bes.opslink.aiops.server.entity.demo.DemoTransfer;
import com.bes.opslink.aiops.server.service.demo.IDemoService;
import com.bes.opslink.aiops.system.api.client.user.UserClient;
import com.bes.opslink.aiops.system.api.dto.user.UserDTO;
import feign.Param;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * web层
 */
@RestController
@RequestMapping("/demo")
@Tag(name = "demo模块", description = "demo相关功能集合")
public class DemoController {

    @Autowired
    private IDemoService demoService;
    @Autowired
    UserClient userClient;

    /**
     * 据据ID查询demo信息
     *
     * @param id 主键ID
     * @return demo对象信息
     */
    @GetMapping("/{id}")
    @Operation(description = "根据demo id查询demo信息")
    public R<DemoDTO> queryById(@Parameter(name = "demo ID") @PathVariable("id") Long id) {
        return R.<DemoDTO>builder()
                .data(DemoTransfer.transfer.toDemoDTO(demoService.getById(id)))
                .build();
    }

    /**
     * 保存demo信息
     *
     * @param demoDTO demo信息
     * @return ID信息
     */
    @PostMapping
    @Operation(description = "插入demo信息")
    public R<Boolean> save(@RequestBody DemoDTO demoDTO) {
        return R.<Boolean>builder()
                .data(demoService.save(DemoTransfer.transfer.toDemo(demoDTO)))
                .build();
    }

    @GetMapping ("/user/1")
    public R<UserDTO> client() {
        return userClient.getById(1L);
    }
}
